import 'package:dio/dio.dart';

class DioOptions {
  static var options = BaseOptions(
      connectTimeout: 15000,
      receiveTimeout: 15000,
      responseType: ResponseType.plain
      // headers: {
      //   'TOKEN': 'header[TOKEN]',
      //   'LOCATION': 'header[LOCATION]',
      // });
      );
}

class DioInterceptor extends Interceptor {
  @override
  Future onRequest(RequestOptions options) {
    // TODO: implement onRequest
    print(
        "\n================================= 请求数据 =================================");
    print("method = ${options.method.toString()}");
    print("url = ${options.uri.toString()}");
    print("headers = ${options.headers}");
    print("params = ${options.queryParameters}");

    return super.onRequest(options);
  }

  @override
  Future onResponse(Response response) {
    // TODO: implement onResponse
    print(
        "\n================================= 响应数据开始 =================================");
    print("code = ${response.statusCode}");
    print("data = ${response.data}");
    print(
        "================================= 响应数据结束 =================================\n");
    return super.onResponse(response);
  }

  @override
  Future onError(DioError e) {
    // TODO: implement onError
    print(
        "\n=================================错误响应数据 =================================");
    print("type = ${e.type}");
    print("message = ${e.message}");
    print("\n");

    return super.onError(e);
  }
}
